cmake_minimum_required(VERSION 2.8)

project(AppleCarPlay C)

set(CMAKE_C_STANDARD 99)

set( CMAKE_C_FLAGS_RELEASE      "${CMAKE_C_FLAGS_RELEASE} -s" )
set( CMAKE_CXX_FLAGS_RELEASE	"${CMAKE_CXX_FLAGS_RELEASE} -s" )
set( CMAKE_BUILD_TYPE			"RELEASE" )

set( Examples           ${PROJECT_SOURCE_DIR} )
set( ACPCP_R16E14       ${Examples}/../ACPCP_R16E14 )
set( fdk-aac            ${Examples}/../fdk-aac-2.0.2 )
set( gdbus              ${Examples}/../gdbus )
set( iAP2               ${Examples}/../iAP2CPP )
set( mDNSResponder      ${Examples}/../mDNSResponder-1310.100.10 )
set( ScreenStream       ${Examples}/../ScreenStream )
set( MessageFramework   ${Examples}/../MessageFramework )
set( SDKTARGETSYSROOT   $ENV{SDKTARGETSYSROOT} )

include_directories(
    ${ACPCP_R16E14}/AccessorySDK/Support
    ${ACPCP_R16E14}/Support
    ${ACPCP_R16E14}/Sources
    ${ACPCP_R16E14}/Platform
    ${ACPCP_R16E14}/build/Release-linux
    ${ACPCP_R16E14}/build/Debug-linux
    ${Examples}
    # CarPlayInterface
    ${gdbus}
    # glib
    ${SDKTARGETSYSROOT}/usr/include/glib-2.0
    ${SDKTARGETSYSROOT}/usr/lib/glib-2.0/include
    ${SDKTARGETSYSROOT}/usr/include/gio-unix-2.0
    ${SDKTARGETSYSROOT}/usr/include/gstreamer-1.0
    # iAP2
    ${iAP2}/include
    ${iAP2}/include/util
    ${SDKTARGETSYSROOT}/usr/include/libusb-1.0
    ${SDKTARGETSYSROOT}/usr/include/c++/7.3.0
    ${SDKTARGETSYSROOT}/usr/include/c++/7.3.0/aarch64-poky-linux
    # MessageFramework
    ${MessageFramework}
    ${ScreenStream}
)

link_directories(
    ${ACPCP_R16E14}/build/Release-linux
    ${ACPCP_R16E14}/build/Debug-linux
    ${mDNSResponder}/mDNSPosix/build/prod
    ${fdk-aac}/build
    ${iAP2}/build
    ${ScreenStream}
    # MessageFramework
    ${MessageFramework}/build
    ${MessageFramework}/libs
    )

aux_source_directory( ${ACPCP_R16E14}/Platform  platform )
list( REMOVE_ITEM platform "${ACPCP_R16E14}/Platform/AudioConverterStub.c" )
list( REMOVE_ITEM platform "${ACPCP_R16E14}/Platform/AudioUtilsStub.c" )
list( REMOVE_ITEM platform "${ACPCP_R16E14}/Platform/ScreenUtilsStub.c" )

aux_source_directory( ${gdbus}/generate         generate )
aux_source_directory( ${gdbus}                  interface )

add_definitions( 
    -DDEBUG_CI=0
    )

####################################################################################
# libCarPlayInterface
####################################################################################

add_library( CarPlayInterface
             SHARED
             ${generate}
             ${interface} )

target_link_libraries(
            CarPlayInterface
            glib-2.0
            gio-2.0
            gobject-2.0 )

####################################################################################
# AppleCarPlay
####################################################################################

add_executable( AppleCarPlay
                ${platform}
                AppleCarPlay_AppStub.c
                iAP2_AppStub.c )

target_link_libraries(
                AppleCarPlay

                CarPlayInterface

                pthread
                dns_sd
                usb-1.0
                AvcStream
                fdk-aac

                iAP2
                sqlite3

                AirPlay
                CoreUtils
                AirPlaySupport
                AudioConverter
                AudioStream
                ScreenStream
                )